<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>await错误处理</title>
  </head>
  <body></body>
  <script src="js/ajax.js"></script>
  <script>
    async function hd(name) {
      //获取用户名
      let user = await ajax(`http://localhost:80/php/user.php?name=${name}`);
      //获取用户课程
      let lessons = await ajax(
        `http://localhost:80/php/houdunren.php?id=${user.id}`
      );
      return lessons;
    }
    //错误可以在外面处理，也可以在里面用try...catch处理
    hd("后盾人")
      .then((lessons) => {
        console.log(lessons);
      })
      .catch((error) => {
        alert(error.message);
      });
  </script>
</html>
